package vista.Parking;

import Utilidades.Errores;
import java.sql.SQLException;
import modelo.entidades.Parking;

/**
 *
 * @author jjcamacho
 */

public class PanelInfoParkingVistaImp extends ParkingVistaImp<Parking> {

    public PanelInfoParkingVistaImp(Parking parking) {
        setEntidad(parking);
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        txtParking = new javax.swing.JTextField();
        txtTipo = new javax.swing.JTextField();
        txtPlazas = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();

        jPanel3.setBackground(new java.awt.Color(0, 0, 0));
        jPanel3.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 255, 51), 3, true));

        jTextField4.setBackground(new java.awt.Color(0, 0, 0));
        jTextField4.setEditable(false);
        jTextField4.setFont(new java.awt.Font("Crystal", 0, 20));
        jTextField4.setForeground(new java.awt.Color(255, 255, 51));
        jTextField4.setText("TIPO:");
        jTextField4.setBorder(null);

        jTextField5.setBackground(new java.awt.Color(0, 0, 0));
        jTextField5.setEditable(false);
        jTextField5.setFont(new java.awt.Font("Crystal", 0, 20));
        jTextField5.setForeground(new java.awt.Color(255, 255, 51));
        jTextField5.setText("PLAZAS:");
        jTextField5.setBorder(null);

        txtParking.setBackground(new java.awt.Color(0, 0, 0));
        txtParking.setEditable(false);
        txtParking.setFont(new java.awt.Font("Crystal", 0, 20));
        txtParking.setForeground(new java.awt.Color(255, 255, 51));
        txtParking.setText("INICIALIZANDO");
        txtParking.setBorder(null);

        txtTipo.setBackground(new java.awt.Color(0, 0, 0));
        txtTipo.setEditable(false);
        txtTipo.setFont(new java.awt.Font("Crystal", 0, 20));
        txtTipo.setForeground(new java.awt.Color(255, 255, 51));
        txtTipo.setBorder(null);

        txtPlazas.setBackground(new java.awt.Color(0, 0, 0));
        txtPlazas.setEditable(false);
        txtPlazas.setFont(new java.awt.Font("Crystal", 0, 20));
        txtPlazas.setForeground(new java.awt.Color(255, 255, 51));
        txtPlazas.setBorder(null);

        jTextField6.setBackground(new java.awt.Color(0, 0, 0));
        jTextField6.setEditable(false);
        jTextField6.setFont(new java.awt.Font("Crystal", 0, 20));
        jTextField6.setForeground(new java.awt.Color(255, 255, 51));
        jTextField6.setText("PARKING:");
        jTextField6.setBorder(null);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(txtPlazas, javax.swing.GroupLayout.DEFAULT_SIZE, 76, Short.MAX_VALUE)
                        .addGap(38, 38, 38))
                    .addComponent(txtTipo, javax.swing.GroupLayout.DEFAULT_SIZE, 114, Short.MAX_VALUE)
                    .addComponent(txtParking, javax.swing.GroupLayout.DEFAULT_SIZE, 114, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtParking, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtPlazas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(113, 113, 113))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField txtParking;
    private javax.swing.JTextField txtPlazas;
    private javax.swing.JTextField txtTipo;
    // End of variables declaration//GEN-END:variables

    @Override
    public void refresh() {
        Parking p = getEntidad(); //si se produce un error en la lectura, al menos se muestra la información actual
        try {
            p = getModel().obtenerEntidad(getEntidad().getNombre());
            setEntidad(p);
        } catch (SQLException ex) {
            Errores.mostrarError(ex);
        } catch (Exception ex) {
            Errores.mostrarError(ex);
        }
        txtParking.setText(p.getNombre().toUpperCase());
        txtPlazas.setText(String.valueOf(p.getPlazasLibres()));
        txtTipo.setText(p.getGrupo().toUpperCase());
    }

}
